﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CTools.Areas.Files.Controllers
{
    public class BarCodeController : CTools.Controllers.BaseController
    {
        // GET: Files/BarCode
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult CreateBarCode(string code)
        {

            Bitmap bmp = Common.Files.BarCode.GetCode39(code);

            //Response.ClearContent();
            //Response.ContentType = "image/jpeg";
            //Response.Buffer = true;
            //Response.ExpiresAbsolute = DateTime.Now.AddMinutes(10);
            //Response.AddHeader("pragma", "no-cache");
            //Response.AddHeader("cache-control", "");
            //Response.CacheControl = "no-cache";
            //System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            //Response.BinaryWrite(ms.ToArray());
            //bmp.Dispose();

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return File(ms.ToArray(), "image/jpeg");
        }
    }
}
